package Dome4;

import java.util.Arrays;
import java.util.Comparator;

public class Text4 {

    public static void main(String[] args) {
       Student wang = new Student("wang", 200);
        Student li = new Student("li", 19);
        Student hu = new Student("hu", 11);
        Student[] students ={wang,li,hu};
        AgecompareTo agecompareTo = new AgecompareTo();
        Arrays.sort(students,agecompareTo);
        System.out.println(Arrays.toString(students));
/* NamecompareTo namecompareTo = new NamecompareTo();
   System.out.println(namecompareTo.compare(wang, li));*/
//        System.out.println(wang.name.compareTo(li.name));

    }
}


class Student {
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

class AgecompareTo implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}

class NamecompareTo implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}